package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle;
import com.corona.Game;
import com.corona.game.util.audio.AudioLoader;

/* compiled from: Action.java */
/* access modifiers changed from: package-private */
/* loaded from: pokewilds.jar:com/pkmngen/game/PlaySound.class */
public class PlaySound extends Action {
    Sound sound;
    float volume;
    int waitFrames;

    public PlaySound(Pokemon pokemon, Action nextAction) {
        super(new Object[0]);
        this.volume = 1.0f;
        this.waitFrames = 0;
        this.nextAction = nextAction;
        this.volume = 0.5f;
        FileHandle file = Gdx.files.internal("mods/pokemon/" + pokemon.specie.name + "/cry.ogg");
        if (!file.exists()) {
            String dexNumber = pokemon.dexNumber;
            if (pokemon.specie.name.equals("araichu")) {
                dexNumber = "raichu-alola";
                this.volume = 1.0f;
            } else if (pokemon.specie.name.equals("aexeggutor")) {
                dexNumber = "exeggutor-alola";
                this.volume = 1.0f;
            } else if (pokemon.specie.name.equals("amarowak")) {
                dexNumber = "marowak-alola";
                this.volume = 1.0f;
            }
            file = Gdx.files.internal("pokemon/cries/" + dexNumber + ".ogg");
        }
        if (pokemon.isEgg) {
            this.sound = AudioLoader.loadSound("sounds/egg_noise1.ogg");
            this.volume = 1.0f;
            this.waitFrames = Specie.cryLengthInFrames("sounds/egg_noise1");
        } else if (pokemon.isGhost) {
            this.sound = AudioLoader.loadSound("pokemon/cries/000.ogg");
            this.volume = 0.5f;
            this.waitFrames = Specie.cryLengthInFrames("pokemon/cries/000");
        } else {
            this.sound = AudioLoader.loadSound(file.path());
            this.waitFrames = pokemon.specie.cryLengthInFrames();
        }
    }

    public PlaySound(String soundName, Action nextAction) {
        this(soundName, 1.0f, nextAction);
    }

    public PlaySound(String soundName, float volume, Action nextAction) {
        super(new Object[0]);
        this.volume = 1.0f;
        this.waitFrames = 0;
        this.nextAction = nextAction;
        this.volume = volume;
        this.sound = null;
        if (!Game.staticGame.loadedSound.containsKey(soundName)) {
            Game.staticGame.loadedSound.put(soundName, AudioLoader.loadSound("sounds/" + soundName + ".ogg"));
        }
        this.sound = Game.staticGame.loadedSound.get(soundName);
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        if (this.sound != null) {
            this.sound.play(this.volume);
        }
        game.insertAction(this.nextAction);
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        int i = this.waitFrames - 1;
        this.waitFrames = i;
        if (i <= 0) {
            game.actionStack.remove(this);
            if (!Game.staticGame.loadedSound.containsValue(this.sound)) {
                this.sound.stop();
                this.sound.dispose();
            }
        }
    }
}
